package com.hilon.foundation.main_child;

import com.hilon.foundation.para.QueryEntity;
import com.hilon.foundation.simple.BaseSimpleController;
import com.hilon.foundation.util.ResultBean;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

public class BaseMainChildController<T extends EntityBaseMain<C,VC>,C extends EntityBaseChild,
        V,
        VC extends EntityBaseChild>
extends BaseSimpleController<T,V> {
    protected BaseMainChildService<T,C,V,VC> service;
    protected void setService(BaseMainChildService<T,C,V,VC> service){
        this.service=service;
        super.setService(service);
    }
    @PostMapping("/getChildrenById/{idPara}")
    public ResultBean<List<C>> getChildrenById(@PathVariable Long idPara) {
        return service.getChildrenById(idPara);
    }
    @PostMapping("/getChildrenFullById/{idPara}")
    public ResultBean<List<VC>> getChildrenFullById(@PathVariable Long idPara) {
        return service.getChildrenFullById(idPara);
    }
    @PostMapping("/deleteChildrenById/{idPara}")
    public void deleteChildrenById(@PathVariable Long idPara) {
        service.deleteChildrenById(idPara);
    }

    @PostMapping("/editChildrenById/{idPara}")
    public void editChildrenById(@PathVariable Long idPara,
                                 @RequestBody List<C> children){
        service.editChildrenById(idPara,children);
    }
    @PostMapping("/appendChildrenById/{idPara}")
    public void appendChildrenById(@PathVariable Long idPara,
                                 @RequestBody List<C> children){
        service.appendChildrenById(idPara,children);
    }
    @PostMapping("/findAllMain")
    public ResultBean<List<V>> findAllMain() {
        return service.findAllMain();
    }

    @PostMapping("/check")
    public ResultBean<String> check(@RequestBody T entity) {
        entity.handleChildren();
        return service.check(entity);
    }
    @PostMapping("/checkCancel")
    public ResultBean<String> checkCancel(@RequestBody T entity) {
        return service.checkCancel(entity);
    }
    @PostMapping("/saveChild")
    public ResultBean<C> saveChild(@RequestBody C child) {
        return service.saveChild(child);
    }
    @PutMapping("/getQueryData/{categoryType}/{entityName}/{categoryName}/{categoryTypeDetail}")
    public ResultBean<List<V>> getQueryData(@PathVariable String categoryType,@PathVariable String entityName,
                                            @PathVariable String categoryName,@PathVariable String categoryTypeDetail,
                                            @RequestBody QueryEntity queryData) {
        return service.getQueryData(categoryType,entityName,categoryName,categoryTypeDetail,queryData);
    }


}
